#pragma once

#include <iostream>
#include <unistd.h>
using namespace std;
#include <string>

class Channel
{
public:
    Channel() = default;
    Channel(int wfd, pid_t who)
        : _wfd(wfd), _who(who)
    {
        _name = "Channel-" + to_string(wfd) + "-" + to_string(who);
    }
    ~Channel()
    {
    }

    int Get_wfd()
    {
        return _wfd;
    }

    void Close()
    {
        close(_wfd);
    }

    void Send(int task)
    {
        write(_wfd,&task,sizeof(task));
    }

    pid_t GetPid()
    {
        return _who;
    }

    string GetName()
    {
        return _name;
    }

private:
    int _wfd;     // 标记每个管道的写端
    string _name; // 管道名
    pid_t _who;
};

